package demo.test;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

public class Json {
    public static void main(String[] args) throws JsonProcessingException {
        ObjectMapper objectMapper = new ObjectMapper();
        String jsonstr = "{\n" +
                "    \"id\":12,\n" +
                "    \"name\":\"ming\",\n" +
                "    \"age\":17\n" +
                "}";
        //JSON字符串转对象
        Student student = objectMapper.readValue(jsonstr,Student.class);
        System.out.println(student);
        //对象转JSON字符串
        String s = objectMapper.writeValueAsString(student);
        System.out.println(s);
    }
}
